package com.gitee.cheungming.consumer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.cheungming.consumer.dao.ConsumerMapper;
import com.gitee.cheungming.consumer.model.Consumer;
import com.gitee.cheungming.consumer.service.IConsumerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Zhang Ming
 * @since 2025-10-27
 */
@Service
public class ConsumerServiceImpl extends ServiceImpl<ConsumerMapper, Consumer> implements IConsumerService {

    @Override
    @Transactional
    public Boolean payByScore(Long consumerId, Long score) {
        Consumer consumer = this.getById(consumerId);
        if (consumer.getScore() >= score) {
            consumer.setScore(consumer.getScore() - score);
            this.updateById(consumer);
            return true;
        }
        throw new RuntimeException("积分不足");
    }
}
